
<template>
  <el-dialog v-model="ifShow" title="提现" width="1000" :before-close="handleCancel">
    <el-form ref="formRef" :model="formData" :rules="rules" label-width="auto" class="demo-ruleForm" status-icon>
      <el-form-item label="操作" prop="op">
        <el-select v-model="formData.op" placeholder="请选择" size="large">
          <el-option :value="1" label="通过"></el-option>
          <el-option :value="2" label="驳回"></el-option>
          <el-option :value="3" label="通过-对公户转账"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="理由" prop="reason">
        <el-input v-model="formData.reason" placeholder="请输入"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleCancel">取消</el-button>
        <el-button type="primary" @click="handleOk">确认</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import CommonApi from "@/api/common";
import MoneyApi from "@/api/money";
import Supplier from "@/api/supplier";

const props = defineProps<{}>();
const emit = defineEmits(["success"]);
const formRef = ref(null);
const formData = reactive({
  id: "",
  op: "",
  reason: "",
});
const rules = reactive({
  op: [{ required: true, message: "请选择!" }],
});
const ifShow = ref(false);

function edit(row: any) {
  nextTick(() => {
    ifShow.value = true;
    Object.assign(formData, row);
  });
}

/**
 * 确定按钮点击事件
 */
async function handleOk() {
  await formRef.value.validate((valid, fields) => {
    if (valid) {
      let data = {
        id: formData.id,
        op: formData.op,
        reason: formData.reason,
      };
      MoneyApi.supplierApproval(data).then((res) => {
        if (res.code == 0) {
          ElMessage.success(res.message);
          formRef.value.resetFields();
          emit("success");
          handleCancel();
        }
      });
    } else {
      console.log("error submit!", fields);
    }
  });
}

/**
 * 取消按钮回调事件
 */
function handleCancel() {
  formRef.value.resetFields();
  ifShow.value = false;
}

defineExpose({
  edit,
});
onMounted(() => {});
</script>
<style lang="scss" scoped>
.container {
  font-size: 16px;
  padding: 14px;
  .info {
    margin-top: 22px;
    .aud {
      margin-top: 14px;
      width: 38%;
    }
  }
}
</style>
